/** @file popup_dialog.cpp
 */
#include "popup_dialog.h"
#include "stdlib.h"
#include "stdio.h"


PopupDialog::PopupDialog(HWND parent):Dialog( parent)
{
    name ="popupDialog";
    activable =0;

}

PopupDialog::~PopupDialog()
{
}

void PopupDialog::draw(Rect *r)
{
    pDC->dirty(max(r->x0,rect.x0), max(r->y0,rect.y0), min(r->x1,rect.x1), min(r->y1,rect.y1));
    Widget::draw(r);
}

int PopupDialog::run()
{
    activeFirstChild();
    
    return Dialog::run();
}

int PopupDialog::eventHandler(HWND hWnd, int iMsg, WPARAM wParam, LPARAM lParam)
{
    switch(iMsg)
    {
    case MSG_KEY_DOWN:
        //Child have the Active status
        if(activeChild)
        {
            sendMessage( activeChild, iMsg, wParam, lParam);
        }
        
        //need key focus
        else
        {
            /// different from widget, only KEY_ENTER valid, KEY_PREV/KEY_NEXT ignored
            switch(wParam)
            {
            case KEY_ENTER:
                activeFirstChild();
                break;
            }
            
        }
        break;
        
    case MSG_KEY_UP:
        if(activeChild)
        {
            sendMessage( activeChild, iMsg, wParam, lParam);
        }
        break;
        
        //father's duty
    case MSG_ACTIVE_ELDER_CHILD:
        activePrevChild();
        break;
        
    case MSG_ACTIVE_YOUNGER_CHILD:
        activeNextChild();
        break;
    }
    
    return 0;
}
